package com.cn.applet.config;


import javax.servlet.http.HttpServletRequest;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

/**
 * 全局异常处理类
 * 
 * @author Dai Zhengtao
 * 
 * @date 2018-06-05
 * 
 * */
@ControllerAdvice
public class GlobalControllerAdvice {

	public static final String DEFAULT_ERROR_VIEW = "/error";

	@ExceptionHandler(value = {Exception.class })
	public ModelAndView defaultErrorHandler(HttpServletRequest req, Exception e) throws Exception {
		
		ModelAndView mav = new ModelAndView();
		mav.addObject("exception", e);
		mav.addObject("url", req.getRequestURL());
		mav.setViewName(DEFAULT_ERROR_VIEW);
		return mav;
	}

}